import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        in.nextLine();
        boolean lenb =true;
        boolean  lexb = true;
        String[] s = new String[n];
        for(int i = 0;i<n;i++){
            s[i] = in.nextLine();
            System.out.println(s[i]);
        }
        for(int i = 1;i<n;i++){
            if(s[i].length()<=s[i-1].length()){
                lenb = false;
            }
        }
        for(int i = 0;i<n-1;i++){
            if(s[i].length()<=s[i+1].length()){
                for(int j =0;j<s[i].length();j++){
                    if(s[i].charAt(j)>s[i+1].charAt(j)){
                        System.out.println("===========1");
                        lexb = false;
                    }
                }
            }
            else {
                for(int j =0;j<s[i+1].length();j++){
                    if(s[i].charAt(j)>s[i+1].charAt(j)){
                        System.out.println("===========2");
                        lexb = false;
                    }
                }
            }
        }
        System.out.println(lexb);
        if(lenb==true&&lexb==true){
            System.out.print("both");
        }
        else if(lenb==true&&lexb!=true){
            System.out.print("lengths");
        }
        else if(lenb!=true&&lexb==true){
            System.out.print("lexicographically");
        }
        else
            System.out.print("none");

    }

}